﻿IF EXISTS (SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME = 'OTMaterialCotizacionUpdate')
	BEGIN
		DROP  Procedure  OTMaterialCotizacionUpdate
	END
GO
CREATE PROCEDURE [dbo].[OTMaterialCotizacionUpdate] 	
	(	
		@Id						AS INT,
		@ArticuloId				AS VARCHAR(13) = NULL,
		@Papel					AS VARCHAR(255) = NULL,
		@TamanoPliegoMaterial	AS VARCHAR(50) = NULL,
		@TamanoPliegoPrensa		AS VARCHAR(50) = NULL,
		@Cantidad				AS DECIMAL(10,2) = 0,
		@Aumento				AS DECIMAL(10,2) = 0,
		@PliegosTotal			AS DECIMAL(10,2) = 0,
		@NoCotizado				AS DECIMAL(10,2) = 0
	)	
AS
BEGIN	
	SET NOCOUNT ON
	
	DECLARE @PliegosPrensaTotal DECIMAL
	
	SET @PliegosPrensaTotal = @Cantidad + @Aumento + @PliegosTotal + @NoCotizado
	
	UPDATE Lit_OTMaterialCotizado
		SET ArticuloId = @ArticuloId,
			Papel = @Papel,
			TamanoPliegoMaterial = @TamanoPliegoMaterial, 
			TamanoPliegoPrensa = @TamanoPliegoPrensa, 
			Cantidad = @Cantidad, 
			Aumento = @Aumento,
			PliegosTotal = @PliegosTotal,
			PliegosPrensaTotal = @PliegosPrensaTotal, 
			NoCotizado = @NoCotizado
	WHERE Id = @Id
	
	SELECT	Id, 
			OTId, 
			ArticuloId, 
			Papel,
			TamanoPliegoMaterial, 
			TamanoPliegoPrensa,
			Cantidad, 
			Aumento,
			PliegosTotal, 
			PliegosPrensaTotal,
			NoCotizado
	FROM Lit_OTMaterialCotizado
	WHERE Id = @Id
		
	SET NOCOUNT OFF
END